package org.ezplatform.office.meeting.setting.boardroom.dao;

import java.util.List;

import org.ezplatform.core.dao.jpa.JpaBaseDao;
import org.ezplatform.office.meeting.setting.boardroom.entity.BoardroomSet;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

@Repository
public interface BoardroomSetDao extends JpaBaseDao<BoardroomSet, String> {

    //验证查询会议名称是否存在
    @Query(value = "from BoardroomSet b where b.id not in(?1) and b.name=?2 and b.corpId=?3")
    List<BoardroomSet> getBoardroomSetByName(String id, String name, String corpId);

  //验证查询会议名称是否存在
    @Query(value = "from BoardroomSet b where b.name=?1 and b.corpId=?2")
    List<BoardroomSet> getBoardroomSetSetByName(String name, String corpId);

    @Query(value = "from BoardroomSet b where  b.corpId=?1 and b.isOpen=1 order by b.sortNo asc,b.createdDate desc")
    List<BoardroomSet> getBoardroomSetList(String corpId);

    @Query(value = "from BoardroomSet b where  b.corpId=?1 and b.isOpen=1 and b.name like %?2% order by b.sortNo asc,b.createdDate desc ")
    List<BoardroomSet> getBoardroomSetList(String corpId, String boardroomName);

    @Query(value = "select b from BoardroomSet b, BoardroomCategorySet bc where b.categoryId = bc.id and  b.corpId=?1 and b.isOpen=1 order by b.sortNo asc,b.createdDate desc")
    List<BoardroomSet> getRealBoardroomSetList(String corpId);
    
    @Query(value = "select b from BoardroomSet b, BoardroomCategorySet bc where b.categoryId = bc.id and b.corpId=?1 and b.isOpen=1 and b.name like %?2% order by b.sortNo asc,b.createdDate desc ")
    List<BoardroomSet> getRealBoardroomSetList(String corpId, String boardroomName);
    
    @Query(value = "from BoardroomSet b where  b.corpId=?1 and b.isOpen=1 and b.progressId is not null order by b.sortNo asc,b.createdDate desc")
    List<BoardroomSet> getBoardroomSetListBpm(String corpId);

    @Query(value = "from BoardroomSet b where  b.corpId=?1 and b.isOpen=1 and b.progressId is not null and b.name like %?2% order by b.sortNo asc,b.createdDate desc ")
    List<BoardroomSet> getBoardroomSetListBpm(String corpId, String boardroomName);
    
    @Query(value = "from BoardroomSet b where b.categoryId in(?1) order by b.sortNo asc,b.createdDate desc")
	List<BoardroomSet> getBoardroomSetList(List<String> categoryIdList);
    
    @Query(value = "from BoardroomSet b where b.categoryId=?1 and b.isOpen=1 order by b.sortNo asc,b.createdDate desc")
    List<BoardroomSet> getBoardroomList(String id);
    
    @Query(value = "from BoardroomSet b where b.categoryId=?1 and b.corpId=?2 and b.isOpen=1 and ((b.isApprove = '1' and b.progressId is not null) or b.isApprove = '0') order by b.sortNo asc,b.createdDate desc")
    List<BoardroomSet> getBoardroomList(String cateId, String corpId);
    
    @Query(value = "from BoardroomSet b where ((b.isApprove='1' and b.progressId is not null) or (b.isApprove='0')) and b.categoryId=?1 and b.isOpen=1 order by b.sortNo asc,b.createdDate desc")
    List<BoardroomSet> getBoardroomListBpm(String id);

}